<template>
  <div class="page-container">
    <!-- 用户信息栏 -->
    <div class="user-info" v-if="userInfo">
      <div class="user-avatar">
        <t-icon name="user" />
      </div>
      <div class="user-details">
        <div class="user-name">{{ userInfo.name }}</div>
        <div class="user-role">{{ userInfo.username }}</div>
      </div>
      <t-button variant="text" size="small" @click="handleLogout">
        退出登录
      </t-button>
    </div>
    
    <div class="page-header">
      <div class="title">精拓肠道菌群项目样本信息单</div>
      <div class="subtitle">请填写完整的样本信息</div>
    </div>
    
    <div class="page-content">
      <div class="welcome-card">
        <div class="welcome-icon">
          <t-icon name="file-text" size="48px" />
        </div>
        <div class="welcome-title">欢迎使用信息填写系统</div>
        <div class="welcome-desc">
          请点击下方按钮开始填写您的样本信息，我们将为您提供专业的服务。
        </div>
      </div>
      
      <div class="info-cards">
        <div class="info-card">
          <div class="card-icon">
            <t-icon name="time" />
          </div>
          <div class="card-content">
            <div class="card-title">快速填写</div>
            <div class="card-desc">简单几步完成信息录入</div>
          </div>
        </div>
        
        <div class="info-card">
          <div class="card-icon">
            <t-icon name="shield" />
          </div>
          <div class="card-content">
            <div class="card-title">信息安全</div>
            <div class="card-desc">您的信息将被安全保护</div>
          </div>
        </div>
        
        <div class="info-card">
          <div class="card-icon">
            <t-icon name="service" />
          </div>
          <div class="card-content">
            <div class="card-title">专业服务</div>
            <div class="card-desc">专业团队为您提供服务</div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="submit-button">
      <t-button theme="primary" size="large" @click="goToForm">
        开始填写
      </t-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { Button as TButton, Icon as TIcon, Dialog, Toast } from 'tdesign-mobile-vue'
import { useAuthStore } from '@/store/auth'

const router = useRouter()
const authStore = useAuthStore()

// 获取用户信息
const userInfo = computed(() => authStore.getUserInfo())

const goToForm = () => {
  router.push('/form')
}

// 退出登录
const handleLogout = () => {
  Dialog.confirm({
    title: '确认退出',
    content: '确定要退出登录吗？',
    confirmBtn: '确定',
    cancelBtn: '取消'
  }).then(() => {
    authStore.logout()
    Toast({
      theme: 'success',
      message: '已退出登录'
    })
    router.push('/login')
  }).catch(() => {
    // 用户取消
  })
}
</script>

<style lang="less" scoped>
.user-info {
  background-color: #fff;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  border-radius: 8px;
  
  .user-avatar {
    width: 40px;
    height: 40px;
    background-color: #f3f3f3;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    color: #0052d9;
  }
  
  .user-details {
    flex: 1;
    
    .user-name {
      font-size: 16px;
      font-weight: 500;
      color: #000;
      margin-bottom: 2px;
    }
    
    .user-role {
      font-size: 12px;
      color: #666;
    }
  }
}

.welcome-card {
  background-color: #fff;
  border-radius: 12px;
  padding: 32px 24px;
  text-align: center;
  margin-bottom: 24px;
  
  .welcome-icon {
    color: #0052d9;
    margin-bottom: 16px;
  }
  
  .welcome-title {
    font-size: 20px;
    font-weight: 500;
    color: #000;
    margin-bottom: 12px;
  }
  
  .welcome-desc {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
  }
}

.info-cards {
  .info-card {
    background-color: #fff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    
    .card-icon {
      width: 40px;
      height: 40px;
      background-color: #f3f3f3;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 16px;
      color: #0052d9;
    }
    
    .card-content {
      flex: 1;
      
      .card-title {
        font-size: 16px;
        font-weight: 500;
        color: #000;
        margin-bottom: 4px;
      }
      
      .card-desc {
        font-size: 12px;
        color: #666;
      }
    }
  }
}
</style>